﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmallERP.Bll.PrintManage;
using SmallERP.MODEL.FoundationModel;
using SmallERP.MODEL.PrintManage;
using Smallerp.Contracts;

namespace SmallERP.PrintManage
{
    public partial class FrmChangeTypeFace : Form
    {
        IOperateDB _OperateDb;
        //public FrmChangeTypeFace(IOperateDB inOp)
        //{
        //    InitializeComponent();
        //    _OperateDb = inOp;
        //}
        public FrmChangeTypeFace(List<BoardModel> inModel, IOperateDB inOp)
        {
            InitializeComponent();
            Model = inModel;
            _OperateDb = inOp;
        }

        private List<BoardModel> Model = null;
        private PaperFaceBLL faceBll ;
        PaperTypeBLL typeBll;
        private BoardBLL _Bbll;
        private void FrmChangeTypeFace_Load(object sender, EventArgs e)
        {
            faceBll = new PaperFaceBLL(_OperateDb);
            typeBll = new PaperTypeBLL(_OperateDb);
            _Bbll = new BoardBLL(_OperateDb);
            comboBoxPaperFace.DataSource = faceBll.GetPaperFaceList();
            comboBoxPaperFace.DisplayMember = "PaperFaceName";
            comboBoxPaperFace.ValueMember = "PaperFaceId";
            comboBoxPaperType.DataSource = typeBll.GetPaperTypeList();
            comboBoxPaperType.DisplayMember = "PaperTypeName";
            comboBoxPaperType.ValueMember = "PaperTypeId";

        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            PaperFace_Info face = (PaperFace_Info) comboBoxPaperFace.SelectedItem;
            //Model.PaperFaceId = face.PaperFaceId;
            Model.ForEach(p => p.PaperFaceId = face.PaperFaceId);
            Model.ForEach(p=>p.PaperFaceName=face.PaperFaceName);
            PaperType_Info type = (PaperType_Info) comboBoxPaperType.SelectedItem;

            Model.ForEach(p => p.PaperTypeId = type.PaperTypeId);
            Model.ForEach(p => p.PaperTypeName = type.PaperTypeName);
            int iCount = 0;
            foreach (BoardModel model in Model)
            {

                int status = _Bbll.UpdateBoardFaceAndType(model);
                if (status == -1)
                {
                   

                }
                else
                {
                  
                    iCount++;
                }

            }
            if (iCount == Model.Count)
            {
                  MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("有 " + (Model.Count - iCount) + " 更新失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
